package com.yuexiao.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yuexiao.entity.ResultInfo;
import com.yuexiao.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName:DishController
 * @Auther: YUEXIAO
 * @Description: 菜品操作控制器
 * @Date: 2022/8/13 17:29
 * @Version: v1.0
 */
@RestController
@Slf4j
@RequestMapping("/dish")
public class DishController {

    @Reference
    private DishService dishService;


    /**
     * 根据分类id查询已上架的菜品
     * @param categoryId Long 分类id
     * @param status int 菜品状态
     * @return ResultInfo 返回结果对象
     */
    @GetMapping("/getListByCid")
    @PreAuthorize("hasAnyRole('ROLE_NOMAL')")
    public ResultInfo getListByCid(Long categoryId,int status){
        return ResultInfo.success(dishService.getDishListByCategoryId(categoryId,status));
    }


    /**
     * 根据套餐id查询菜品数据
     * @param sid
     * @return
     */
    @GetMapping("/getListBySid/{sid}")
    @PreAuthorize("hasAnyRole('ROLE_NOMAL')")
    public ResultInfo getListBySid(@PathVariable Long sid){
        return ResultInfo.success(dishService.getDishListBySetmealId(sid));
    }


}
